package com.iot.service;

import com.iot.mapper.DTwatchMapper;
import com.iot.mapper.TwatchMapper;
import com.iot.pojo.MTwatch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class TwatchServiceImpl implements TwatchService {
    @Autowired
    private TwatchMapper mapper;
    @Autowired
    private DTwatchMapper dmapper;

    @Override
    public int getRecordCount(String sWhere) {
        return mapper.getRecordCount(sWhere);
    }

    @Override
    public int insert(MTwatch mTwatch) throws Exception {

        int count = 0;
        count = getRecordCount(" AND SDATE='" + mTwatch.getSDATE() + "' AND EMP_ID=" + mTwatch.getEMP_ID() + "");
        if (count > 0)
            throw new Exception("该记录已存在");
        return mapper.insert(mTwatch);
    }

    @Override
    public void update(MTwatch mTwatch) throws Exception {
        int count = 0;
        count = getRecordCount(" AND SDATE='" + mTwatch.getSDATE() + "' AND EMP_ID=" + mTwatch.getEMP_ID() + "  AND WATCH_ID!=" + mTwatch.getWATCH_ID() + "");
        if (count > 0)
            throw new Exception("该记录已存在");
        mapper.update(mTwatch);
    }

    @Override
    public void deleteById(int id) {
        mapper.deleteById(id);
    }

    @Override
    public MTwatch single(Integer id) {
        return mapper.single(id);
    }

    @Override
    public List<MTwatch> fetch(String sWhere) {
        return mapper.fetch(sWhere);
    }

    @Override
    public List<Map<String, Object>> fetchByPage(Map<String, Object> map) {

        return dmapper.fetchByPage(map);
    }


}
